﻿@model Zor_Web.Models.Systems.V_Users
@using Webdiyer.WebControls.Mvc;
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>用户管理</title>
    <link href="~/Content/LayerUI/src/css/layui.css" rel="stylesheet" />
    <link href="~/Content/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="~/Content/Styles/zor.css" rel="stylesheet" />
    <!-- 框架必要 -->
    <script src="~/Content/Scripts/jquery/jquery-1.9.1.min.js"></script>
    <script src="~/Content/Scripts/learunui-framework.js"></script>
    <script src="~/Content/Scripts/Zor_AJax.js"></script>
    <!-- 消息提示 -->
    <script language='javascript' src='~/Content/layer/layer.js'></script>
    <!-- 表单验证 -->
    <script src="~/Content/Scripts/JValidator.js"></script> 
</head>
<body>

    <div class="layui-tab layui-tab-brief main-tab-container ">
        <div class="col-sm-12 ct-padding">
            <div class="col-sm-9 ct-padding">
                <button id="btnAdd" class="layui-btn layui-btn-normal layui-btn-small"><span class="glyphicon glyphicon-plus"></span> 新增</button>
                <button id="btnUpdate" class="layui-btn layui-btn-warm layui-btn-small"><span class="glyphicon glyphicon-pencil"></span> 编辑</button>
                <button id="btnDelete" class="layui-btn layui-btn-danger layui-btn-small"><span class="glyphicon glyphicon-trash"></span> 删除</button>
                <button id="btnUnlock" class="layui-btn layui-btn-danger layui-btn-small"><span class="glyphicon glyphicon-refresh"></span> 解冻账户</button>
            </div>
            <div class="col-sm-3 ct-padding">
                <div class="input-group">
                    <input id="inputWhere" type="text" placeholder="请输入用户名" autocomplete="off" class="form-control">
                    <span class="input-group-btn">
                        <button id="btnSearch" class="btn btn-info" type="button"><span class="glyphicon glyphicon-search"></span> 搜索</button>
                    </span>
                </div>
            </div>
        </div>

        <div class="layui-tab-content">
            <table class="layui-table" lay-skin="line">
                <thead>
                    <tr>
                        <th hidden></th>
                        <th><input type="checkbox" name="checkAll" id="cbkCheckAll"></th>
                        <th>用户名</th>
                        <th>所属角色</th>
                        <th>所属部门</th>
                        <th>真实姓名</th>
                        <th>是否超管</th>
                        <th>是否启用</th>

                    </tr>
                </thead>
                <tbody id="accordion">
                    @foreach (var item in Model.PageData)
                    {
                        <tr>
                            <td hidden>@item.User_Id</td>
                            <td><input type="checkbox" class="i-checks" name="chk" id="@item.User_Id" value="@item.User_Id" /></td>
                            <td>@item.User_UserName</td>
                            <td>@item.Role_Name</td>
                            <td>@item.Dt_Name</td>
                            <td>@item.User_RealName</td>
                            <td>@item.IsAdmin</td>
                            <td>@item.IsVisibleName</td>
                            <td hidden>@item.DT_Id</td>
                            <td hidden>@item.Roles_Id</td>
                            <td hidden>@item.User_Phone</td>
                            <td hidden>@item.Is_Admin</td>
                            <td hidden>@item.Is_Available</td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>

        <div class="col-sm-12">
            <div class="col-sm-10">
                @Html.Pager(Model.PageData, new PagerOptions { PageIndexParameterName = "index", ContainerTagName = "ul", PrevPageText = "上页", NextPageText = "下页", FirstPageText = "首页", LastPageText = "尾页", CssClass = "pagination", PagerItemsSeperator = "", CurrentPagerItemWrapperFormatString = "<li class=\"active\"><a href=\"#\">{0}</a></li>", PagerItemWrapperFormatString = "<li>{0}</li>" }, new { id = "bootstrappager", @class = "pagination" })
            </div>
            <div class="col-sm-2 to-righjt">
                共 @Model.PageData.TotalItemCount 条记录，页 @Model.PageData.CurrentPageIndex/@Model.PageData.TotalPageCount
            </div>
        </div>

    </div>
    <!-- 模态 -->
    <div id="myModal" hidden data-backdrop="static">
        <div id="divfrom" class="layui-tab-content">
            <form class="form-horizontal m-t">
                <div class="layui-form-item" hidden>
                    <label class="col-sm-3 layui-form-label">用户Id：</label>
                    <div class="col-sm-8">
                        <input id="User_Id" type="text" class="form-control">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="col-sm-3 layui-form-label">用户名：</label>
                    <div class="col-sm-8">
                        <input id="User_UserName" type="text" class="form-control" placeholder="请输入用户名" autofocus="autofocus" datacol="yes" err="用户名" checkexpession="NotNull">
                    </div>
                </div>
                <div class="layui-form-item" id="divRoles">
                    <label class="col-sm-3 layui-form-label">所属角色：</label>
                    <div class="col-sm-8">
                        <select name="temp" class="form-control" id="Roles_Id">
                            <option value="-1">- 请选择 -</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item" id="divDt">
                    <label class="col-sm-3 layui-form-label">所属部门：</label>
                    <div class="col-sm-8">
                        <select name="temp" class="form-control" id="DT_Id">
                            <option value="-1">- 请选择 -</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="col-sm-3 layui-form-label">真实姓名：</label>
                    <div class="col-sm-8">
                        <input id="User_RealName" type="text" class="form-control" placeholder="请输入真实姓名" autofocus="autofocus" datacol="yes" err="真实姓名" checkexpession="NotNull">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="col-sm-3 layui-form-label">联系电话：</label>
                    <div class="col-sm-8">
                        <input id="User_Phone" type="text" class="form-control" placeholder="请输入联系电话" autofocus="autofocus" datacol="yes" err="联系电话" checkexpession="MobileOrPhone">
                    </div>
                </div>
                <div class="layui-form-item" id="divisadmin">
                    <label class="col-sm-3 layui-form-label">是否是超管：</label>
                    <div class="col-sm-8">
                        <select name="temp" class="form-control" id="Is_Admin">
                            <option value="-1">- 请选择 -</option>
                            <option value="2">否</option>
                            <option value="1">是</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item" id="divIs_Available">
                    <label class="col-sm-3 layui-form-label">是否启用：</label>
                    <div class="col-sm-8">
                        <select name="temp" class="form-control" id="Is_Available">
                            <option value="-1">- 请选择 -</option>
                            <option value="1">是</option>
                            <option value="2">否</option>
                        </select>
                    </div>
                </div>
            </form>
        </div>

        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <div class="col-sm-11 ">
                <button id="btnSure" class="btn btn-info pull-right">
                    <i class="fa fa-check"></i>提交
                </button>
            </div>
        </div>

    </div>



</body>
<script>

    /* 查询所有角色 */

    function GetAccordionRolse() {
        var html = "<option value='-1'>- 请选择 -</option>";
        getAjax("/Systems/SelectRolse", "", function (data) {
            accordionJson = eval("(" + data + ")");
            $.each(accordionJson, function (i) {
                html += "<option value='" + accordionJson[i].Roles_Id + "' >" + accordionJson[i].Role_Name + "</option>";
            });
        });
        $("#Roles_Id").empty().append(html);
    }

    /* 查询所有部门树形展示*/

    function GetAccordionDepSelectNavTree() {
        var html = "<option value='-1'>- 请选择 -</option>";
        getAjax("/Systems/SelectDepartmentTree", "", function (data) {
            accordionJson = eval("(" + data + ")");
            $.each(accordionJson, function (i) {
                html += "<option value='" + accordionJson[i].Dt_Id + "' >" + accordionJson[i].LevName + "</option>";
            });
        });
        $("#DT_Id").empty().append(html);
    }


    $(function () {

        /* 增加用户*/

        $("#btnAdd").click(function () {
            ClearWebControls(divfrom);
            GetAccordionRolse();                               //加载所有权限
            GetAccordionDepSelectNavTree();                   //加载所有部门
            LayerOpen('650px', '580px', '用户新增', $('#myModal'));
        })

        /* 修改用户*/

        $("#btnUpdate").click(function () {
            var checkId = CheckboxValueIDs();
            $("#User_UserName").attr("readonly", "readonly");
            if (checkId.length == 0) {
                layer.msg("请选择要修改的信息！");
                return;
            }
            if (checkId.length > 1) {
                layer.msg("仅可选择一行信息修改！");
                return;
            }
            GetAccordionRolse();                                //加载所有权限
            GetAccordionDepSelectNavTree();                   //加载所有部门
            $("#User_Id").val(checkId[0]);           
            $("#User_UserName").val(getTableCell(2)); 
            $("#Role_Name").val(getTableCell(3));
            $("#Dt_Name").val(getTableCell(4));
            $("#User_RealName").val(getTableCell(5));
            $("#IsAdmin").val(getTableCell(6));
            $("#IsVisibleName").val(getTableCell(7));
            $("#DT_Id").val(getTableCell(8));
            $("#Roles_Id").val(getTableCell(9));
            $("#User_Phone").val(getTableCell(10));
            $("#Is_Admin").val(getTableCell(11));
            $("#Is_Available").val(getTableCell(12));
            LayerOpen('650px', '580px', '用户修改', $('#myModal'));
        })

        /*保存*/

        $("#btnSure").click(function () {
            if (!CheckDataValid('.form-horizontal')) {
                return false;
            }          
            var JsData = GetWebControls(divfrom);
            ZorPostSimpleData("/Systems/AddAlterSysUser", JSON.stringify({ "sysuser": JsData }), function (data) {
                layer.msg(data.AnswerMeg, function () {
                    layer.closeAll();
                    Replace();
                });
            });
        })

        /*** 设置账户为可用*/
        $("#btnUnlock").click(function () {
            var checkId = CheckboxValueIDs();
            if (checkId.length == 0) {
                layer.msg("请选择不可用的账户！");
                return;
            }
            else {
                layer.confirm("确定要设置为可用账号吗?", { icon: 2, btn: ['确定', '取消'] }, function () {
                    ZorPostSimpleData("/Systems/UnlockUser", JSON.stringify({ 'Id': checkId }), function (data) {
                        layer.msg(data.AnswerMeg, function () {
                            layer.closeAll();
                            Replace();
                        });
                    })
                })
            }
        })

        /* 删除用户*/
        $("#btnDelete").click(function () {
            var checkId = CheckboxValueIDs();
            if (checkId.length == 0) {
                layer.msg("请选择要删除的用户！");                                                             //未选中任何行
                return;
            }
            else {
                layer.confirm("确定要删除吗?", { icon: 2, btn: ['确定', '取消'] }, function () {
                    ZorPostSimpleData("/Systems/UserDeleteSysUser", JSON.stringify({ 'Id': checkId }), function (data) { //获取数据(带参数)
                        layer.msg(data.AnswerMeg, function () {
                            layer.closeAll();
                            Replace();
                        });
                    })
                })
            }
        })
    })

    /**
     * 全选
     */
    $(function () {
        $("#cbkCheckAll").click(function () {
            if (this.checked) {
                $("input[name='chk']").prop('checked', true);
            } else {
                $("input[name='chk']").prop('checked', false);
            }
        })
    })


</script>

</html>



